#!/bin/bash
current=$(swww query | head -1 | awk '{print $NF}' )
wallpaperpath=$HOME/Pictures/BingWallpaper/
echo $wallpaperpath
echo $current
python $HOME/.config/eww/scripts/bing-get.py

if [[ $? -eq 0 ]]; then
    next=$(find "$wallpaperpath" -maxdepth 1 -type f -not -path '*/.*' -printf '%T+\t%p\n' | sort -k 1 -r | head -1 | awk '{print $NF}')
else
    next=$(find "$wallpaperpath" -maxdepth 1 -type f -not -path '*/.*' | shuf -n 1)
fi
swww img $next --transition-fps 60 --transition-type random --transition-pos "${cursorposx:-0}, ${cursorposy_inverted:-0}"
ln -sf $next $HOME/.config/eww/images/wallpaper
